<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>layui</title>
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
</head>
<body>
    <form class="" action="#">
        <div class="">
            <label class="layui-form-label">所属商家:</label>
            <div class="">
                <select id="shop_id" name="shop_id" style="height: 100%">
                    <foreach name="shop" item="vo">
                        <option value="{$vo.shop_id}" <if condition="$vo['shop_id'] == $list['shop_id']">selected</if>>{$vo.name}</option>
                    </foreach>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品名称:</label>
            <div class="layui-input-block">
                <input id="title" type="text" name="title" class="layui-input" value="{$list.title}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">价格:</label>
            <div class="layui-input-block">
                <input id="price" type="text" name="price" class="layui-input" value="{$list.price}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">详情:</label>
            <div class="layui-input-block">
                <script id="container" name="content" type="text/plain">{$list.content}</script>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button id="updateGoods" class="layui-btn" lay-submit="" lay-filter="*">立即提交</button>
            </div>
        </div>
        <input id="id" type="hidden" value="{$list.id}">
    </form>
    <!-- 配置文件 -->
    <script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.all.js"></script>
    <!-- 实例化编辑器 -->
    <script type="text/javascript">
        var editor = UE.getEditor('container');
    </script>
    <script src="__PUBLIC__/layui/layui.js" charset="utf-8"></script>
    <script src="__PUBLIC__/js/jquery-1.11.1.min.js" charset="utf-8"></script>
    <script type="text/javascript">
        $(function(){
            var editor = UE.getEditor('container');
            $('#updateGoods').click(function(){
                $.ajax({
                    type: "POST",
                    url: "update",
                    data: {id:$('#id').val(), shop_id:$("#shop_id").val(), title:$("#title").val(), price:$("#price").val(), content: editor.getContent()},
                    dataType: "json",
                    success: function(res) {
                        if (res == 1) {
                            alert('修改成功!')
                            parent.location.reload();
                        } else {
                            alert('未作修改或修改失败!')
                            parent.location.reload();
                        }
                    },
                    error: function(res) {
                        alert('修改错误!');
                        parent.location.reload();
                    }
                });
            });
        });
    </script>
</body>
</html>